/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uloha4.controller;

import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import uloha4.view.MagicCanvas;

/**
 *
 * @author Tomique
 */
public class ScaleController implements MouseWheelListener {

    private final double INCREMENT = 0.1;
    private final double MIN_SCALE = 0.15;
    private MagicCanvas canvas;

    public ScaleController() {
        canvas = MagicCanvas.getInstance();
    }

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {

            double zoom = -e.getWheelRotation() * INCREMENT;
            // pouze v pripade, ze oddaleni neni temer nulove ho povolim
            if (canvas.getScale() > MIN_SCALE || zoom > 0.0) {
                // prictu k aktualni hodnote zoomu
                canvas.addScale(zoom);
                // prekreslim canvas
                canvas.repaint();
            }
        }
    }
}